package cn.tedu.zhwy.community.service.impl;

import cn.tedu.zhwy.community.mapper.CommunityMapper;
import cn.tedu.zhwy.community.pojo.dto.RepairsQuery;
import cn.tedu.zhwy.community.pojo.entity.Repairs;
import cn.tedu.zhwy.community.pojo.vo.RepairsVO;
import cn.tedu.zhwy.community.service.CommunityService;
import cn.tedu.zhwy.workspase.mapper.WorkSpaceMapper;
import cn.tedu.zhwy.workspase.pojo.entity.Landlord;
import cn.tedu.zhwy.workspase.pojo.vo.LamdlordVO;
import cn.tedu.zhwy.workspase.service.WorkSpaceService;
import cn.tedu.zhwy.workspase.service.impl.WorkSpaceServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class CommunityServiceImpl implements CommunityService {
    @Autowired
    CommunityMapper communityMapper;
    @Autowired
    WorkSpaceMapper workSpaceMapper;

    @Override
    public List<RepairsVO> selectList(RepairsQuery repairsQuery) {
        log.debug("开始处理查询报修业务，参数：{}",repairsQuery);
        if (repairsQuery.getLname()!=null){
            LamdlordVO lamdlordVO = workSpaceMapper.selectbyname(repairsQuery.getLname());
            repairsQuery.setRlid(lamdlordVO.getLid());
        }
        log.debug("s{}",repairsQuery.getRlid());
        List<RepairsVO> list = communityMapper.selectList(repairsQuery);
        /*for (RepairsVO repairsVO : list){
            String lname= repairsVO.getLname();
            if (lname==null){
                repairsVO.setLname("无");
            }
            String householdNum= repairsVO.getHouseholdNum();
            if (householdNum==null){
                repairsVO.setRhouse("无");
            }
        }*/
        return list;
    }
    @Override
    public void add(RepairsQuery repairsQuery) {
        log.debug("开始处理添加报修业务，参数：{}",repairsQuery);
        Repairs repairs = new Repairs();
        /*LamdlordVO lamdlordVO = workSpaceMapper.selectbyname(repairsQuery.getLname());
        repairsQuery.setRlid(lamdlordVO.getLid());
        log.debug("报修人id：{}",lamdlordVO.getLid());*/
        BeanUtils.copyProperties(repairsQuery,repairs);
        if (repairs.getRid()==null){
            repairs.setRtime(new Date());
           /* repairs.setRstate("待维修");*/
            communityMapper.add(repairs);
        }else {
            repairs.setRtime(new Date());
            communityMapper.update(repairs);
        }
    }

    @Override
    public void delete(Integer rid) {
        communityMapper.delete(rid);
    }

    @Override
    public void update(Integer rid) {
        Repairs repairs = new Repairs();
        repairs.setRid(rid);
        communityMapper.update(repairs);
    }

}
